var $_G = $_G || {};
var $_V = $_V || {};

(function ($) {
	'use strict';
	
	
		var ViewRule =[
					[
						"Node_1_1",
					],
					[
						"Node_2_1",
						"Node_2_2",
						"Node_2_3"
					],
					[
						"Node_3_1",
                        "Node_3_2",
                        "Node_3_3",
                        "Node_3_4",
                        "Node_3_5"
					]
				];
	
	
	
	function Global(){
		this.tempView = null;
		this.swapHeight = $(window).height() - 150;

        $(".SwapGroupOut").height($(window).height() - 150);

	}
	
	// Global.prototype.getNearValue = function(value){
		// var widths = this.widths;
		
		// if (widths.length === 0) { return 0; }
		// this.widths = widths.sort(function(a,b){return a-b;});
		// console.log(widths);
		// var obj = {};
		// obj.left = 0;
		// obj.right = 0;
		
		// var len = widths.length;
		// for (var i = 0; i < len; i++) {
			// if (widths[i] > value) {
				// obj.right = widths[i];
				// return obj;
			// }
				// obj.left = widths[i];
		// }
		
		// return obj;
	// };
	
	Global.prototype.getNewView = function(index,len){
	
	
		var residue = len - index;
		var canpalce = residue >=3 ? 3 : residue;
		var max = Math.floor(Math.random()*canpalce);
		var viewlen = ViewRule[max].length;
		var randView = Math.floor(Math.random()*viewlen);
		return ViewRule[max][randView];
	
	};
	
	Global.prototype.getView = function(index,len){
		
		// console.log(this.checkView());
		// console.log(index + " @ "+len  +" :: "+this.checkView());
		
		if(this.checkView()){
			var newViewName = this.getNewView(index,len);
			this.tempView = new $_V[newViewName]();
			// console.log("&&&&&&&&&&& "+newViewName);
			// console.log(this.tempView);
		}
		// console.log(this.tempView);
		return this.tempView;
	};
	
	Global.prototype.checkView = function(){
		// console.log(this.tempView === null || this.tempView.isFull());
		return this.tempView === null || this.tempView.isFull();
	};
	
	
	$_G = new Global();
	
})(jQuery);